package com.coke.spring.seata.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.coke.spring.seata.entity.Stock;
import com.coke.spring.seata.service.StockService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author cwm
 * @Description TODO
 * @date 2021/9/3 下午3:13
 * @Version 1.0
 */
@RestController
@AllArgsConstructor
public class StockController {
    private final StockService service;

    /**
     * 根据商品id减库存
     * @param productId
     */
    @PutMapping("/stock/{productId}")
    public void stock(@PathVariable("productId") Integer productId){
        Stock stock = service.getById(productId);
        service.update(stock,Wrappers.<Stock>lambdaUpdate()
                .eq(Stock::getProductId,productId));
    }

    @GetMapping("/test")
    public String test(){
        return "stock-server";
    }
}
